<template>
  <van-swipe class="my-swipe" 
  :autoplay="3000" 
  indicator-color="white" 
   ref="swipeTo">
    <van-swipe-item v-for="url in imgs" :key="url.bannerid">
      <img :src="url.img" />
    </van-swipe-item>
    <!--    <van-swipe-item>2</van-swipe-item>
    <van-swipe-item>3</van-swipe-item>
    <van-swipe-item>4</van-swipe-item> -->
  </van-swipe>
</template>

<script>
import axios from "axios";
export default {
  name: "BannerSwiper",
  data() {
    return {
      imgs: [],
    };
  },

  //从后端拿到数据（数据绑定之后）
  created() {
    axios({
      url: "/api/banner/list",
    }).then((res) => {
      let data = res.data;
      // console.log("data: ", data);
      if (data.code == 200) {
        this.imgs = data.data;
      }
    });
  },
};
</script>

<style scoped>
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  text-align: center;
}
img {
  width: 100%;
  border-radius: 15px;
}
</style>